import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/widgets/bottom_input_widget.dart';
import 'package:ls_work/widgets/title_value_widget.dart';

import '../../model/meter_reading_model.dart';

class SubmitMeterReadingViewModel extends BaseViewModel {
  final String? roomId;
  final String? lastNumber;

  SubmitMeterReadingViewModel(BuildContext context,
      {this.roomId, this.lastNumber})
      : super(context);

  var model = MeterReadingModel();

  var ordinalNumber = "";

  Widget contentView() {
    return Column(
      children: [
        CommonText('抄表', textSize: 18)
            .addToContainer(margin: EdgeInsets.symmetric(vertical: 15)),
        TitleValueWidget(
          "上次读数",
          text: lastNumber ?? "--",
          showArrow: false,
        ),
        TitleValueWidget(
          "本次读数",
          text: ordinalNumber,
          isRequired: true,
          hint: '请输入本次读数',
        ).onTap(() {
          showBottomInput(context, content: ordinalNumber, onSubmit: (str) {
            ordinalNumber = str;
            notifyListeners();
          }, keyboard: CommonInputType.numberAndDecimal);
        }),
        Container().setWeight(1),
        ElevatedButton(onPressed: () {
          submitMeter();
        }, child: Text("提交抄表")).addToContainer(
            width: double.infinity,
            margin: EdgeInsets.symmetric(horizontal: 16, vertical: 13))
      ],
    );
  }

  Future<void> submitMeter() async {
    if(ordinalNumber.isNullOrEmpty()){
      showToast("请输入本次抄表");
      return;
    }
    showLoadingDialog(msg: '提交中...');
    // try{
    //   var data = await model.submitMeterReading(roomId, ordinalNumber);
    //   hideDialog();
    // }catch(e){
    //   showToast(NetErrorUtils.getNetError(e));
    //   hideDialog();
    // }
  }
}
